﻿@{
    ViewBag.Title = "产品编辑";
    var product = ViewBag.Product as CubicFWNet.Data.Models.Product;
    var categorys = ViewBag.CategoryList as List<CubicFWNet.Data.Models.Category>;
}

<section class="content-header">
    <h1>
        产品编辑
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">产品编辑</li>
    </ol>
</section>

<section class="content">
    <form class="form-horizontal" method="post" id="formMain">
        <div class="box box-solid">
            <div class="box-body">
                <div class="row">
                    <input type="hidden" name="Id" value="@product.Id" />
                    @*<input type="hidden" id="modalData" value="@product.Data">*@
                    @*<input type="hidden" id="Data" name="Data" />*@
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Name" class="col-sm-3 control-label">产品名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Name" name="Name" value="@product.Name" maxlength="200">
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Number" class="col-sm-3 control-label">产品编号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Number" name="Number" value="@product.Number" maxlength="50">
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="WorkType" class="col-sm-3 control-label">分类</label>
                        <div class="col-sm-9">
                            <select class="form-control" id="CategoryId" name="CategoryId">
                                @if (categorys != null)
                                {
                                    foreach (var item in categorys)
                                    {
                                        if (product.CategoryId == item.Id)
                                        {
                                            <option selected value="@item.Id">@item.Name</option>
                                        }
                                        else
                                        {
                                            <option value="@item.Id">@item.Name</option>
                                        }
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="WorkType" class="col-sm-3 control-label">执行部门</label>
                        <div class="col-sm-9">
                            <select class="form-control" id="ExecuteDepartment" name="ExecuteDepartment">
                                @if (product.ExecuteDepartment == 1)
                                {
                                    <option value="1" selected="selected">工厂</option>
                                    <option value="2">采购</option>
                                }
                                else if (product.ExecuteDepartment == 2)
                                {
                                    <option value="1">工厂</option>
                                    <option value="2" selected="selected">采购</option>
                                }
                                else
                                {
                                    <option value="1">工厂</option>
                                    <option value="2">采购</option>
                                }
                            </select>
                        </div>
                    </div>
                    @*<div class="form-group col-md-6 col-sm-12">
                            <label for="WorkType" class="col-sm-3 control-label">加工方式</label>
                            <div class="col-sm-9">
                                <select class="form-control" id="WorkType" name="WorkType">
                                    @if (product.WorkType == 1)
                                    {
                                        <option value="1" selected="selected">模切</option>
                                        <option value="2">切卷</option>
                                    }
                                    else if (product.WorkType == 2)
                                    {
                                        <option value="1">模切</option>
                                        <option value="2" selected="selected">切卷</option>
                                    }
                                </select>
                            </div>
                        </div>*@

                    @*<div class="form-group col-md-6 col-sm-12">
                            <label for="Pack" class="col-sm-3 control-label">枚/张</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="Pack" name="Pack" value="@product.Pack" maxlength="50" />
                            </div>
                        </div>*@
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Unit" class="col-sm-3 control-label">基本单位</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Unit" name="Unit" value="@product.Unit" maxlength="50" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Format" class="col-sm-3 control-label">产品规格</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Format" name="Format" maxlength="50" value="@product.Format" />
                        </div>
                    </div>
                    @*<div class="form-group col-md-6 col-sm-12">
                            <label for="PackRequire" class="col-sm-3 control-label">包装要求</label>
                            <div class="col-sm-9">
                                <select class="form-control" id="PackRequire" name="PackRequire">
                                    @if (product.PackRequire == 1)
                                    {
                                        <option value="1" selected>平张</option>
                                        <option value="2">卷筒</option>
                                    }
                                    else if (product.PackRequire == 2)
                                    {
                                        <option value="1">平张</option>
                                        <option value="2" selected>卷筒</option>
                                    }
                                </select>
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="PackAmount" class="col-sm-3 control-label">包装数量</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="PackAmount" name="PackAmount" value="@product.PackAmount" maxlength="20" />
                            </div>
                        </div>*@

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="SizeWidth" class="col-sm-3 control-label">宽度-mm</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="SizeWidth" name="SizeWidth" value="@product.SizeWidth" maxlength="64" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="SizeLenth" class="col-sm-3 control-label">长度-mm</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="SizeLenth" name="SizeLenth" value="@product.SizeLenth" maxlength="64" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Price" class="col-sm-3 control-label">内部价格</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="Price" name="Price" value="@product.Price" maxlength="20" />
                        </div>
                    </div>

                    @*<div id="json-content">
                            <div class="form-group col-md-6 col-sm-12" style="display:none">
                                <label for="Quantity" class="col-sm-3 control-label">起订量[PCS]</label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="Quantity" name="Quantity" data-des="起订量[PCS]" value="@product.Quantity" maxlength="20" />
                                </div>
                            </div>
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="Color" class="col-sm-3 control-label">颜色</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Color" name="Color" data-des="颜色" maxlength="50" value="@product.Color" />
                                </div>
                            </div>
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="Angel" class="col-sm-3 control-label">角度</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Angel" name="Angel" data-des="角度" value="@product.Angel" maxlength="50" />
                                </div>
                            </div>
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="Tolerance" class="col-sm-3 control-label">正公差-mm</label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="Tolerance" name="Tolerance" data-des="公差-mm" value="@product.Tolerance" maxlength="20" />
                                </div>
                            </div>
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="ToleranceMinus" class="col-sm-3 control-label">负公差-mm</label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="ToleranceMinus" name="ToleranceMinus" data-des="公差-mm" value="@product.ToleranceMinus" maxlength="20" />
                                </div>
                            </div>
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="Space" class="col-sm-3 control-label">左右间距-mm</label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="Space" name="Space" data-des="左右间距-mm" value="@product.Space" maxlength="20" />
                                </div>
                            </div>
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="Margin" class="col-sm-3 control-label">左右边距-mm</label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="Margin" name="Margin" data-des="左右边距-mm" value="@product.Margin" maxlength="20" />
                                </div>
                            </div>
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="Distance" class="col-sm-3 control-label">跳距-mm</label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="Distance" name="Distance" data-des="跳距-mm" value="@product.Distance" maxlength="20" />
                                </div>
                            </div>
                        </div>*@
                </div>
                <div class="row">
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Creator" class="col-sm-3 control-label">创建人</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Creator" name="RealName" value="@product.CreatorName" readonly="readonly" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="CreateTime" class="col-sm-3 control-label">创建时间</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="CreateTime" value="@product.CreateTime" readonly="readonly" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="box-footer">
                <div class="box-footer">
                    <span class="btn btn-primary" onclick="FormSub()" id="btnOk">确 定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a class="btn btn-primary" href="@Url.Action("Index","Product")">返 回</a>
                </div>
            </div>
        </div>
    </form>
</section>

@section Scripts {
    <script type="text/javascript">
        //$(document).ready(function () {
        //    //解析Data数据
        //    var data = JSON.parse(document.getElementById("modalData").value);
        //    var $content = $('#json-content');
        //    var html = "";
        //    data.forEach(function (e, i) {
        //        if (typeof e.value == "undefined") {
        //            e.value = "";
        //        }
        //        if (typeof e.name == "undefined") {
        //            e.name = "";
        //        }
        //        if (typeof e.des == "undefined") {
        //            e.des = "未知";
        //        }
        //        html += "<div class='form-group col-md-6'>";
        //        html += "<label for='j_a' class='col-sm-3 control-label'>" + e.des + "</label>";
        //        html += "<div class='col-sm-9'>";
        //        html += "<input type='text' class='form-control' data-des='" + e.des + "' id='" + e.name + "' name='" + e.name + "' value='" + e.value + "' >";
        //        html += "</div></div>";
        //    });
        //    $content.append(html);
        //})


        //保存Data数据
        //function getParam() {
        //    var postdata = [];
        //    //主键
        //    $("#json-content").find('input,select,textarea').each(function (r) {
        //        var $this = $(this);
        //        var id = $this.attr('id');
        //        var type = $this.attr('type');
        //        if (id) {
        //            switch (type) {
        //                case "checkbox":
        //                    postdata.push({ des: $this.attr("data-des"), name: id, value: $this.is(":checked") });
        //                    break;
        //                case "select":
        //                    var value = $this.find("option:selected").val() == "" ? null : $this.find("option:selected").val();
        //                    postdata.push({ des: $this.attr("data-des"), name: id, value: value });
        //                    break;
        //                default:
        //                    var value = $this.val() == "" ? "&nbsp;" : $this.val();
        //                    postdata.push({ des: $this.attr("data-des"), name: id, value: value });
        //                    break;
        //            }
        //        }
        //    });
        //    return JSON.stringify(postdata);
        //}

        //提交表单
        function FormSub() {
            var name = $("#Name").val().trim();
            if (name == "") {
                $.modalAlert("请输入产品名称", "warning");
                return false;
            }
            var number = $("#Number").val().trim();
            if (number == "") {
                $.modalAlert("请输入产品编号", "warning");
                return false;
            }
            var width = $("#SizeWidth").val().trim();
            if (width == "") {
                $.modalAlert("请输入产品宽度", "warning");
                return false;
            }
            var length = $("#SizeLenth").val().trim();
            if (length == "") {
                $.modalAlert("请输入产品长度", "warning");
                return false;
            }

            var price = $("#Price").val().trim();
            if (price == "") {
                $.modalAlert("请输入产品内部价格", "warning");
                return false;
            }
            //var data = getParam();
            //$("#Data").val(data);
            $("#btnOk").attr('disabled', "true")
            $("#formMain").submit();
        }
    </script>
}